/**
 * @Author:  renyc
 * @Date: 2022-11-30 13:13:00
 */

class LayerCollection{

    constructor(){
        this._cache = {};
    }

    /**
     * 添加图层
     * @param {*} layer 
     */
    add(layer){
        if(layer){
            this._cache[layer.name] = layer;
        }
    }

    remove(layer){
        if(!layer){
            return;
        }
        if(!this.find(layer.name)){
            delete this._cache[layer.name];
        }
    }

    /**
     * 根据Layer的名称获取Layer
     * @param {String} name 
     * @returns {Layer}对象的引用
     */
    find(name){        
        return this._cache[name];
    }

    getLayers(){
        let layers = [];
        Object.keys(this._cache).forEach(name=>{
            layers.push(this._cache[name]);
        });
        return layers;
    }
}

export default LayerCollection
